package com.sucker.infoservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sucker.commonutils.R;
import com.sucker.infoservice.entity.Userinfo;
import com.sucker.infoservice.service.UserinfoService;
import com.sucker.shiroservice.utils.TokenUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户
 * </p>
 *
 * @author sucker
 * @since 2022-07-04
 */
@Tag(name = "UserinfoController",description = "用户管理")
@RestController
@RequestMapping("/infoservice/userinfo")
@CrossOrigin
public class UserinfoController {

    @Autowired
    private UserinfoService userinfoService;


    /**
     * 登录
     * @param userinfo
     * @return
     */
    @Operation(summary = "登录")
    @PostMapping("loginByPhone")
    public R loginByPhone(@Parameter(description = "用户信息对象") @RequestBody Userinfo userinfo){

        //查询用户
        Userinfo user = userinfoService.getOne(new QueryWrapper<Userinfo>().eq("phone", userinfo.getPhone()));
        if(user == null) return R.error().message("用户不存在");

        //判断密码
        if(user.getPassword().equals(userinfo.getPassword())) {
            user.setPassword("xxx");
            return R.ok().message("登录成功").data("user",user);
        }
        else return R.error().message("登录失败");
    }



}

